package cn.seaboot.commons.file;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import cn.seaboot.commons.core.Asserts;

/**
 * 脚本引擎工具
 *
 * @author Mr.css
 * @version 2024-11-13 11:22
 */
public class ScriptEngineUtils {

    private ScriptEngineUtils(){}

    /**
     * 返回 python 解析引擎，依赖 jython-standalone-2.7.4
     *
     * @return 脚本引擎
     */
    public static ScriptEngine createPythonEngine() {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("python");
        Asserts.notNull(engine, "dependency is require: jython-standalone");
        return engine;
    }

    /**
     * 返回 javascript 解析引擎，支持 ECMAScript 5.1
     *
     * @return 脚本引擎
     */
    public static ScriptEngine createJavascriptEngine() {
        ScriptEngineManager manager = new ScriptEngineManager();
        return manager.getEngineByName("JavaScript");
    }
}
